package net.ceviz.forum.java;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class HttpClient {

	public static void main(String[] args) {
		try {
			Socket socket = new Socket("www.ceviz.net", 80);
			OutputStream os = socket.getOutputStream();
			PrintWriter writer = new PrintWriter(os);
			String crlf = "\r\n";
			writer.write("GET / HTTP/1.1" + crlf);
			writer.write("Host: www.ceviz.net:80" + crlf);
			writer.write("User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" + crlf);
			writer.write("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + crlf);
			writer.write("Accept-Language: en-us,en;q=0.5" + crlf);
			writer.write("Accept-Encoding: gzip, deflate" + crlf);
			writer.write("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + crlf);
			writer.write("DNT: 1" + crlf);
			writer.write("Connection: keep-alive" + crlf);
			writer.write(crlf + crlf);
			writer.flush();
			
			InputStream is = socket.getInputStream();
			BufferedReader reader = new BufferedReader(new InputStreamReader(is));
			String line = null;
			while( (line=reader.readLine()) != null ) {
				System.out.println(line);
			}
			reader.close();
			
			socket.close();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
